package com.hyb.weibo.common.vo;

import com.hyb.weibo.common.enums.MessageEnum;

public class JsonResult {
    private Integer code;
    private Object data;
    private String msg;

    public JsonResult() {
        this.code= MessageEnum.OK.getCode();
        this.msg=MessageEnum.OK.getMsg();
    }

    public JsonResult(Object data) {
        this.code= MessageEnum.OK.getCode();
        this.msg=MessageEnum.OK.getMsg();
        this.data = data;
    }

    public JsonResult(Object data,String msg) {
        this.code= MessageEnum.OK.getCode();
        this.msg=msg;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static JsonResult ok(){
        return new JsonResult();
    }
    public static JsonResult ok(Object data){
        return new JsonResult(data);
    }
    public static JsonResult ok(Object data,String msg){
        return new JsonResult(data,msg);
    }
    public static JsonResult ok(Object data,MessageEnum messageEnum){
        return new JsonResult(data,messageEnum.getMsg());
    }
    /**
     * 服务器错误
     * @param msg
     * @return
     */
    public static JsonResult err(String msg){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg(msg);
        jsonResult.setCode(500);
        return jsonResult;
    }

/*    public static JsonResult build(Integer code,String msg){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg(msg);
        jsonResult.setCode(code);
        return jsonResult;
    }*/

    /**
     * 构建
     * @param messageEnum
     * @return
     */
    public static JsonResult build(MessageEnum messageEnum){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg(messageEnum.getMsg());
        jsonResult.setCode(messageEnum.getCode());
        return jsonResult;
    }
}
